package com.sgb.kjwl.viewmodel.enterprise;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.EnterpriseAPIManager;
import com.sgb.kjwl.model.entity.ParentAreaEntity;
import com.sgb.kjwl.view.ui.activity.enterprise.ProfessionalQuoteActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ProfessionalQuoteModel extends BaseViewModel {
    private ProfessionalQuoteActivity professionalQuoteActivity;

    public ProfessionalQuoteModel(ProfessionalQuoteActivity professionalQuoteActivity) {
        this.professionalQuoteActivity = professionalQuoteActivity;
    }

    /**
     * 获取服务类别
     */
    public void getServiceType() {
        DialogHelper.showProgressDialog(professionalQuoteActivity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getServiceCategoryOption().enqueue(new Callback<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>>>> call, Response<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    MToast.showToast(professionalQuoteActivity, "暂无数据");
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    professionalQuoteActivity.showTypeView(response.body().getData());
                } else {
                    MToast.showToast(professionalQuoteActivity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }
}
